package com.imooc.hadoop.mapreduce.MultipleInputs;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @program: hadoop
 * @description: MultipleInputReducer
 * @author: zengchen
 * @create: 2021-04-01 09:01
 **/
public class MultipleInputReducer extends Reducer<Text, LongWritable, Text, NullWritable> {

    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        long count = 0;
        for (LongWritable value : values) {
            count += value.get();
        }
        context.write(new Text(key+","+count), NullWritable.get());
    }
}
